package com.briup;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by dell on 2017/9/29.
 */
//@WebServlet(name = "LoginServlet",value={"/login"})
//@WebServlet(name = "LoginServlet",urlPatterns={"/login"})
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //request.setCharacterEncoding("gbk");
        //response.setCharacterEncoding("gbk");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer=response.getWriter();

        String username=request.getParameter("username");
        StringBuilder text=new StringBuilder();
        text.append("<message>");
        if(username==null||username.equals("")){
           text.append("<i>*</i>对不起，您输入的名字为空").append("</message>");
        }else{
            if(username.equals("wangzhao")){
                text.append("<i>*</i>用户名["+username+"]已经存在，请使用其他用户").append("</message>");
            }else {
                text.append("<i>*</i>用户名["+username+"]尚未存在，可以使用该用户").append("</message>");
            }
        }
        writer.print(text.toString());
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
    }
}
